package com.easypoi.service.impl;

import com.easypoi.service.PersonServer;
import com.easypoi.mapper.PersonMapper;
import com.easypoi.entity.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/** @author HKC */
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Service
public class PersonServerImpl implements PersonServer {
  @Autowired private PersonMapper personMapper;

  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  @Override
  public List<Person> selectAll() {
    List<Person> personList = personMapper.selectAll();
    if (personList != null && personList.size() > 0) {
      return personList;
    }
    return null;
  }

  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  @Override
  public Person findByNameAndPassword(String username, String password) {

    Person person = personMapper.selectByPerson(username, password);
    if (person != null) {
      return person;
    }
    return null;
  }

  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  @Override
  public int saveImport(Person person) {
    return personMapper.insertSelective(person);
  }
}
